package io.karl.code_gen.config;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import lombok.Data;

import java.net.URL;
import java.util.Map;

@Data
public class ConfigProperties {

    private Map<String, DataSourceConfig> dataSource;

    /**
     * 使用哪个数据源
     */
    private String useDataSource;

    /**
     * 指定生成的表，多个表使用','分隔
     */
    private String includeTables;

    /**
     * 包名配置
     */
    private PackageConfig packageName;

    /**
     * 逻辑删除列名
     */
    private String deleteColumn;

    /**
     * 作者
     */
    private String author;

    /**
     * 输出目录
     */
    private String outputDir;

    public static ConfigProperties parse() {
        ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
        URL fileUri = ConfigProperties.class.getClassLoader().getResource("application.yml");
        try {
            return mapper.readValue(fileUri, ConfigProperties.class);
        } catch (Exception e) {
            System.out.println("config parse failed: " + e.getMessage());
            return null;
        }
    }
}
